﻿<?php

// vim: expandtab shiftwidth=2 softtabstop=2 tabstop=2

/**
 * Group of functions to various jobs
 *
 * PHP version 5
 *
 * @category  Namespaces
 * @package   mPack
 * @author    Marcin Sztolcman <marcin /at/ urzenia /dot/ net>
 * @copyright 2006 Marcin Sztolcman
 * @license   GPL v.2
 * @version   SVN: $Id: ns_tools.php 29 2008-01-20 23:15:20Z urzenia $
 * @link      http://m-pack.googlecode.com
 */

/**
 * Group of functions to various jobs
 *
 * @category  Namespaces
 * @package   mPack
 * @author    Marcin Sztolcman <marcin /at/ urzenia /dot/ net>
 * @copyright 2006 Marcin Sztolcman
 * @license   GPL v.2
 * @version   SVN: $Id: ns_tools.php 29 2008-01-20 23:15:20Z urzenia $
 * @link      http://m-pack.googlecode.com
 */
abstract class Tools
{
  /**
   * Check for $min < $i < $max
   *
   * @param double $i
   * @param double $min
   * @param double $max
   *
   * @return boolean
   * @static
   */
  public static function inRange($i, $min, $max)
  {
    return ($min < $i && $i < $max);
  }

  /**
   * Replacement for core {@link http://php.net/sprintf sprintf()}
   *
   * As first parameter must be supplied string which have to be prepared.
   * If second param is an array, it's keys will be used as pattern, and values
   * as replacement for {@link http://php.net/str_replace str_relace()}
   * function.
   * In other case, all params will be passed to {@link http://php.net/sprintf sprintf()}
   * and returned.
   *
   * @param ,... mixed
   *
   * @return string
   * @static
   */
  public static function sprintf()
  {
    $args = func_get_args();
    if (!$args) {
      throw new InvalidArgumentException('String to parse needed.', XXX);
    }
    $s = array_shift($args);

    if (!$args) {
      return $s;
    }

    if (is_array($args[0])) {
      return strtr($s, $args);
    } else {
      array_unshift($args, $s);
      return call_user_func_array('sprintf', $args);
    }
  }

}

?>
